﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace MethodWorx.CMS
{
    public class AssemblyResourceReference
    {
        private string name;

        public AssemblyResourceReference(Assembly assembly, string name)
        {
            bool found = false;
            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                if (resourceName.EndsWith(name.Replace("/", ".")))
                {
                    this.name = string.Format("~/_AssemblyResource/{0}/{1}", assembly.GetName().Name, resourceName);
                    found = true;
                }
            }

            if (!found)
                throw new Exception("Could not find resource: " + name);
        }

        public string Name
        {
            get { return this.name; }
        }
    }
}
